import { RouteObject } from "react-router-dom"
import { componentMap } from "@/router/routerMap"
interface MenuType{
    icon: string,
    key: string,
    label: string,
    children?:MenuType[]
}

function GeneratesRoutes(menu:MenuType[]):RouteObject[]{
    return menu.map((item:MenuType)=>{
        const hasChidren=item.children
        let routerObj:RouteObject={
            path:item.key,
            element: hasChidren ? null :<>{componentMap[item.key]}</>
        }
        if(item.children){
            routerObj.children=GeneratesRoutes(item.children)
        }

        return routerObj
    })
}

export default GeneratesRoutes